<template>
<div>
  <el-container>
    <el-header>
      <el-button @click="toadd">添加</el-button>
    </el-header>
    <el-table>
    </el-table>
    <el-dialog title="添加申请" :visible.sync="showadd">
        <el-form :model="form">
          <el-form-item label="名称" label-width="120">
            <el-input v-model="form.areaname" autocomplete="off"></el-input><input type="button" @click="showarea" value="点击"/>
          </el-form-item>
          <el-form-item label="服务名称" label-width="120">
            <el-select v-model="form.serviceId" placeholder="请选择">
              <el-option
                v-for="item in dicServices"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="提供者id" label-width="120">
            <el-select v-model="form.providerid" placeholder="请选择">
              <el-option
                v-for="item in dicProviders"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        <el-form-item label="运营商" label-width="120">
          <el-select v-model="form.operationId" placeholder="请选择">
            <el-option
              v-for="item in dicOperations"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
          <el-form-item label-width="120">
            <el-button @click="save" type="warning">保存</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    <el-dialog title="选择区域" :visible.sync="areaShow">
      <el-container>
        <el-header>
          <el-container><el-input v-model="search.key"></el-input><input type="button" @click="queryArea" value="查询"/></el-container>
        </el-header>
        <el-table
          ref="singleTable"
          :data="areaList"
          highlight-current-row
          @current-change="selOne"
          style="width: 100%">
          <el-table-column
            type="index"
            width="50">
          </el-table-column>
          <el-table-column
            property="id"
            label="序号"
            width="120">
          </el-table-column>
          <el-table-column
            property="name"
            label="名称"
            width="120">
          </el-table-column>
        </el-table>
        <el-footer>
          <div class="block">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page.sync="search.page"
              :page-size="search.pageSize"
              layout="total, prev, pager, next"
              :total="search.total">
            </el-pagination>
          </div>
        </el-footer>
      </el-container>
    </el-dialog>
  </el-container>
</div>
</template>

<script>
export default {
  name: 'OrderManView',
  data () {
    return {
      areaShow: false,
      showadd: false,
      // 保存分页以及查询的关键字
      search: {
        page: 1,
        pageSize: 5,
        key: '',
        total: 0
      },
      // 字典表数据
      dics: [],
      // 区域列表
      areaList: [],
      form: {
        area: {
          areaname: '',
          areaId: 0,
          providerid: 0,
          serviceId: 0,
          operationId: 0
        }
      }
    }
  },
  /**
   * 计算字段
   */
  computed: {
    // 服务名称
    dicServices () {
      return this.dics.filter(x => { return x.type === 1 })
    },
    dicOperations () {
      return this.dics.filter(x => { return x.type === 2 })
    },
    dicProviders () {
      return this.dics.filter(x => { return x.type === 3 })
    }
  },
  methods: {
    /**
     * 保存下拉框
     * @param val
     */
    save () {
      this.axios.post('/order/save', this.form).then(res => {
        if (res.data.code === 200) {
          this.$message('保存成功')
        }
      })
    },
    handleSizeChange (val) {
      this.search.pageSize = val
      this.queryArea()
    },
    handleCurrentChange (val) {
      this.search.page = val
      this.queryArea()
    },
    // 选中的区域
    selOne (val) {
      this.form.areaname = val.name
      this.form.areaId = val.id
      this.areaShow = false
    },
    // 查询区域
    queryArea () {
      this.axios.post('/dic/areaList', this.search).then(res => {
        this.areaList = res.data.records // 查询所有数据
        this.search.pageSize = res.data.size
        this.search.total = res.data.total
        this.search.page = res.data.current
      })
    },
    // 显示区域
    showarea () {
      alert('aa')
      this.areaShow = true
    },
    // 去增加
    toadd () {
      this.showadd = true
    }
  },
  created () {
    this.axios.get('/dic/list4').then(res => {
      this.dics = res.data
    })
  }
}
</script>

<style scoped>

</style>
